//author:dhclly
const o =console.log;

interface Bird {
    fly();
    layEggs();
}

interface Fish {
    swim();
    layEggs();
}

class NFish implements Fish{
    swim=()=>{};
    layEggs=()=>{};
}

function getSmallPet(): Fish | Bird {
    // ...
    return new NFish()|{fly:()=>{},layEggs:()=>{}}
}

let pet = getSmallPet();

if ((<Fish>pet).swim) {
    (<Fish>pet).swim();
}
else {
    (<Bird>pet).fly();
}